package org.noote.libs.assistant.analyse;

import java.util.ArrayList;

public class Element {

	static public enum Type
	{
		AUCUN,
		PONCTUATION,
		MOT
	};
	
	String _element;
	Type _type=Type.AUCUN;
	
	Element_Mot _mot=null;
	ArrayList<Element_Mot_Possibilite> _listeMotPossible=new ArrayList<Element_Mot_Possibilite>();
	
	private Element_Ponctuation _ponctuation=null;
	ArrayList<Element_Ponctuation> _listePonctuationPossible=new ArrayList<Element_Ponctuation>();
	
	public Element()
	{
	}
	
	public Element(Element_Ponctuation ponc)
	{
		this._element = ponc._element;
		this._type=Type.PONCTUATION;
		_ponctuation=ponc;
	}
	
	public Element(Element_Mot mot)
	{
		this._element = mot._element;
		this._type=Type.MOT;
		_mot=mot;
	}
	
	public String getElement()
	{
		return _element;
	}
	public Type getType()
	{
		return _type;
	}
	public Element_Ponctuation getAsPonctuation()
	{
		return _ponctuation;
	}
	public Element_Mot getAsMot()
	{
		return _mot;
	}
	public boolean kindOf(Element el)
	{
		if(this._type != el._type) return false;
		if(this._element.equalsIgnoreCase(el._element)) return true;

		return false;
	}
	public boolean kindOf(String el)
	{
		if(this._element.equalsIgnoreCase(el)) return true;

		return false;
	}
	
	@Override
	public String toString()
	{
		String elFormat="";
		switch(_type)
		{
		case PONCTUATION:
			 elFormat += "p(";
			 elFormat += getAsPonctuation().toString();
			 elFormat += ") ";
			 break;
		case MOT:
			 elFormat += "m(";
			 elFormat += getAsMot().toString();
			 elFormat += ") ";
			 break;
		default:
			elFormat += "?(" + getElement() + ") ";
			break;
		}
		return elFormat;
	}
	
	public static Element analyse(Ponctuation ponctuation, Dictionnaire dictionnaire, String element)
	{
		Element el = new Element();
		el._element = element;
		
		// is ponctuation ?
		if(ponctuation.check(element, el._listePonctuationPossible)>0)
		{
			if(el._listePonctuationPossible.size() == 1)
			{
				el._ponctuation = el._listePonctuationPossible.get(0);
				el._type = Type.PONCTUATION;
			}
		}
		else
		{
			// is a word mark ?
			if(dictionnaire.check(element, el._listeMotPossible)>0)
			{
				if(el._listeMotPossible.size() == 1)
				{
					el._mot = el._listeMotPossible.get(0)._element;
					el._type = Type.MOT;
				}
			}
		}
		
		return el;
	}
}
